package bavaria.hightech.money;

public class Money {

	private long betrag;
	private Waehrung currency;
	
	public Money(long betrag, Waehrung waehrung){
		this.betrag = betrag;
		this.currency = waehrung;
	}
	
	
	
	public long getBetrag() {
		return betrag;
	}



	public Waehrung getCurrency() {
		return currency;
	}



	public Money add(Money money){
		if(currency == money.getCurrency())
			return new Money(betrag + money.getBetrag(), currency);
		else
			return add(convert(money));
	}
	

	
	private Money convert(Money money){
		if(currency == Waehrung.EUR){
			if(money.getCurrency() == Waehrung.GBP)
				return new Money((long)(money.getBetrag()*1.2), currency);
			else
				return new Money((long)(money.getBetrag()*0.8), currency);
		}
		else if(currency == Waehrung.GBP){
			if(money.getCurrency() == Waehrung.EUR)
				return new Money((long)(money.getBetrag()*0.8), currency);
			else
				return new Money((long)(money.getBetrag()*0.6), currency);
		}
		else if(currency == Waehrung.USD){
			if(money.getCurrency() == Waehrung.EUR)
				return new Money((long)(money.getBetrag()*1.3), currency);
			else
				return new Money((long)(money.getBetrag()*1.5), currency);
		}
		else
			return null;
	}
	
	public boolean gleichheit(Money money){
		if(currency == money.getCurrency() && betrag == money.getBetrag())
			return true;
		else if(currency != money.getCurrency()){
			return gleichheit(convert(money));
		}
			
		else
			return false;
	}
	
	public boolean bigger(Money money){
		if(currency == money.getCurrency() && betrag > money.getBetrag())
			return true;	
		else if(currency != money.getCurrency())
			return bigger(convert(money));
		else
			return false;
	}
	
	public String toString(){
		String s = betrag + " " + currency;
		return s;
	}
	
	public int compareTo(Money geld){
		if(bigger(geld)){
			return 1;
		}
		else if(gleichheit(geld))
			return 0;
		else 
			return -1;
	}
	
	public static void main(String []args){
		Money money1 = new Money(300, Waehrung.EUR);
		Money money2 = new Money(400, Waehrung.EUR);
		Money money3 = new Money(500, Waehrung.USD);
		
		System.out.println(money1.add(money2).toString());
		System.out.println(money1.add(money3).toString());
		
	}
}
